package com.gitee.wsl.time


import kotlinx.datetime.DateTimeUnit
import kotlinx.datetime.LocalDate
import kotlinx.datetime.plus

 class LocalDateRange(
    override val start: LocalDate,
    override val endInclusive: LocalDate,
    private val stepDays: Long = 1
) : Iterable<LocalDate>, ClosedRange<LocalDate> {

    override fun iterator(): Iterator<LocalDate> =
        LocalDateIterator(start, endInclusive, stepDays)

     infix fun step(days: Long): LocalDateRange = LocalDateRange(start, endInclusive, days)
}

 operator fun LocalDate.rangeTo(other: LocalDate) = LocalDateRange(this, other)

 class LocalDateIterator(
    startDate: LocalDate,
    private val endDate: LocalDate,
    private val stepDays: Long
) : Iterator<LocalDate> {
    private var currentDate = startDate

    override fun hasNext(): Boolean = currentDate <= endDate

    override fun next(): LocalDate {
        val next = currentDate
        currentDate = currentDate.plus(stepDays, DateTimeUnit.DAY)
        return next
    }
}